package alp.starcode.nudtportal.framework.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

import java.time.Duration;

/**
 * @author: lw
 * @date: 2021/5/25 11:13
 * @description:
 */
@Configuration
public class RestTemplateConfig {

    @Autowired
    RestTemplateBuilder restTemplateBuilder;

    @Value("${rest-template.connect-timeout}")
    private String connectTimeout;

    @Value("${rest-template.read-timeout}")
    private String readTimeout;


    @Bean
    public RestTemplate restTemplate() {
        return restTemplateBuilder.setConnectTimeout(Duration.ofMillis(Integer.parseInt(connectTimeout)))
                .setReadTimeout(Duration.ofMillis(Integer.parseInt(readTimeout))).build();
    }


}
